package com.beadhouse.nurfile.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.beadhouse.common.dto.JSONResponse;
import com.beadhouse.common.dto.QueryResult;
import com.beadhouse.common.exeption.BeadHouseException;
import com.beadhouse.entity.NurLevelEntity;
import com.beadhouse.entity.NursingFileEntity;
import com.beadhouse.nurfile.ao.AddNurFileAO;
import com.beadhouse.nurfile.ao.NursingFileAO;
import com.beadhouse.nurfile.ao.SelectNurFileAO;
import com.beadhouse.nurfile.service.NursingFileService;
import com.beadhouse.nurlevel.service.NurLevelService;

@Controller
@RequestMapping("/api/nurfile")
public class NurFileController {
	@Autowired
	NursingFileService nfService;
	@Autowired
	NurLevelService nlServce;
	
	@GetMapping("/query")
	public ModelAndView selectNurFile(SelectNurFileAO ao) throws Exception {
			ModelAndView mav=new ModelAndView();	
			List<NursingFileEntity> r=nfService.selectNursingFile(ao);
			mav.setViewName("nurfile/nursingFile");
			mav.addObject("data", r);
			return mav;
	
	}
	
	@PostMapping("/add")
	public String addNurLevelFile(AddNurFileAO ao) throws Exception {
		nfService.addNursingFile(ao);
		int levelId=Integer.parseInt(ao.getLevelId());
		int customerId=Integer.parseInt(ao.getCustomerId());
		nfService.addCustomerLevel(levelId, customerId);
		return "redirect:/api/nurfile/query?customerId="+ao.getCustomerId()+"#"+ao.getCustomerId();
	}
	
	@PostMapping("/selectlevel")
	@ResponseBody
	public JSONResponse selectAllNurLevel() throws Exception {
		QueryResult<NurLevelEntity> result=nlServce.selectAll();
		return JSONResponse.ok(result);
	}
}
